package org.example;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Service
public class ConversationContextService {
    private final Map<String, String> conversationContexts = new HashMap<>();

    /**
     * 创建新会话
     * @return 会话ID
     */
    public String createNewConversation() {
        String conversationId = UUID.randomUUID().toString();
        conversationContexts.put(conversationId, "");
        return conversationId;
    }

    /**
     * 获取会话上下文
     * @param conversationId 会话ID
     * @return 上下文内容
     */
    public String getContext(String conversationId) {
        return conversationContexts.getOrDefault(conversationId, "");
    }

    /**
     * 更新会话上下文
     * @param conversationId 会话ID
     * @param newContext 新的上下文内容
     */
    public void updateContext(String conversationId, String newContext) {
        if (conversationContexts.containsKey(conversationId)) {
            conversationContexts.put(conversationId, newContext);
        }
    }

    /**
     * 清除会话上下文
     * @param conversationId 会话ID
     */
    public void clearContext(String conversationId) {
        conversationContexts.remove(conversationId);
    }
}